package com.yanfan.access.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.access.domain.NjAccessDeviceInfo;
import com.yanfan.access.service.INjAccessDeviceInfoService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 门禁设备信息Controller
 *
 * @author genluo
 * @date 2024-10-29
 */
@Api(tags = "门禁设备信息")
@RestController
@RequestMapping("/access/accessDeviceInfo")
public class NjAccessDeviceInfoController extends BaseController {
    @Autowired
    private INjAccessDeviceInfoService njAccessDeviceInfoService;

    /**
     * 查询门禁设备信息列表
     */
    @ApiOperation("门禁设备信息分页列表")
    @PreAuthorize("@ss.hasPermi('access:accessDeviceInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjAccessDeviceInfo njAccessDeviceInfo) {
        startPage();
        List<NjAccessDeviceInfo> list = njAccessDeviceInfoService.queryPageList(njAccessDeviceInfo);
        return getDataTable(list);
    }

    /**
     * 导出门禁设备信息列表
     */
    @ApiOperation("导出门禁设备信息列表")
    @PreAuthorize("@ss.hasPermi('access:accessDeviceInfo:export')")
    @Log(title = "门禁设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjAccessDeviceInfo njAccessDeviceInfo) {
        List<NjAccessDeviceInfo> list = njAccessDeviceInfoService.queryPageList(njAccessDeviceInfo);
        ExcelUtil<NjAccessDeviceInfo> util = new ExcelUtil<NjAccessDeviceInfo>(NjAccessDeviceInfo.class);
        util.exportExcel(response, list, "门禁设备信息数据");
    }

    /**
     * 获取门禁设备信息详细信息
     */
    @ApiOperation("获取门禁设备信息详细信息")
    @PreAuthorize("@ss.hasPermi('access:accessDeviceInfo:query')")
    @GetMapping(value = "/{deviceCode}")
    public AjaxResult getInfo(@PathVariable("deviceCode") String deviceCode) {
        return success(njAccessDeviceInfoService.getById(deviceCode));
    }

    /**
     * 新增门禁设备信息
     */
    @ApiOperation("新增门禁设备信息")
    @PreAuthorize("@ss.hasPermi('access:accessDeviceInfo:add')")
    @Log(title = "门禁设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody NjAccessDeviceInfo njAccessDeviceInfo) {
        njAccessDeviceInfo.setCreateTime(DateUtils.getTimestamp());
        return toAjax(njAccessDeviceInfoService.save(njAccessDeviceInfo));
    }

    /**
     * 修改门禁设备信息
     */
    @ApiOperation("修改门禁设备信息")
    @PreAuthorize("@ss.hasPermi('access:accessDeviceInfo:edit')")
    @Log(title = "门禁设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody NjAccessDeviceInfo njAccessDeviceInfo) {
        njAccessDeviceInfo.setUpdateTime(DateUtils.getTimestamp());
        return toAjax(njAccessDeviceInfoService.updateById(njAccessDeviceInfo));
    }

    /**
     * 删除门禁设备信息
     */
    @ApiOperation("删除门禁设备信息")
    @PreAuthorize("@ss.hasPermi('access:accessDeviceInfo:remove')")
    @Log(title = "门禁设备信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deviceCodes}")
    public AjaxResult remove(@PathVariable String[] deviceCodes) {
        return toAjax(njAccessDeviceInfoService.removeBatchByIds(Arrays.asList(deviceCodes)));
    }
}
